package com.qianfeng.zw.meilishuo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.qianfeng.zw.meilishuo.R;
import com.qianfeng.zw.meilishuo.bean.TwitterGoods;
import com.qianfeng.zw.meilishuo.utils.ImageLoaderHelper;

import java.util.List;

/**
 * @Package com.qianfeng.zw.meilishuo.adapter
 * @作 用:
 * @创 建 人: zhangwei
 * @日 期: 15/4/9 22:21
 * @修 改 人:
 * @日 期:
 */
public class HotSellAdapter extends BaseAdapter {
    private List<TwitterGoods> list;
    private Context context;
    LayoutInflater inflater;
    private DisplayImageOptions options;

    public HotSellAdapter(List<TwitterGoods> list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
        options = ImageLoaderHelper.getInstance().getDefaultPicDisplayImageOptions();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TwitterGoods item = list.get(position);
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_home_hotsell_layout, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        ImageLoader.getInstance().displayImage(item.getPicUrl(), vh.img,options);
        vh.remarkTv.setText(item.getRemark());
        vh.priceTv.setText(item.getTitle());
        vh.likeTv.setText(item.getCountLike());
        return convertView;
    }


    private class ViewHolder {
        @ViewInject(R.id.home_hotsell_img)
        ImageView img;
        @ViewInject(R.id.home_hotsell_remark)
        TextView remarkTv;
        @ViewInject(R.id.home_hotsell_price)
        TextView priceTv;
        @ViewInject(R.id.home_hotsell_like)
        TextView likeTv;

        public ViewHolder(View itemView) {
            ViewUtils.inject(this, itemView);
        }
    }


}
